package com.example.servlet;

import com.example.Service.NewsService;
import com.example.pojo.News;
import com.google.gson.Gson;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@WebServlet(name = "GetTendingServlet", value = "/GetTendingServlet")
public class GetTendingServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {

        NewsService ns= new NewsService();
        List<News> list= ns.getTrendingNews();
        Map<String,Object> m =new HashMap<>() ;
        m.put("code",200);
        m.put("msg","查询成功");
        m.put("data",list);
        Gson gson =new Gson();
        String json =gson.toJson(m);
        response.getWriter().append(json);
    }

    public void destroy() {
    }
}